﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using HYCodeBase.WinForm;

namespace HangerSupport
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class cmdReverSeismicComponent : HYNoTranExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public override void FilterProcess()
		{
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)4);
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)117);
            base.FilterViewType.Add((Autodesk.Revit.DB.ViewType)3);
			base.FilterProcess();
		}

		public override Result HYExecute()
		{
			bool flag = cmdReverSeismicComponent.wndRevit == null;
			if (flag)
			{
				Process currentProcess = Process.GetCurrentProcess();
				cmdReverSeismicComponent.wndRevit = new WindowHandle(currentProcess.MainWindowHandle);
			}
			int wMsg = 7;
			cmdReverSeismicComponent.SendMessage(cmdReverSeismicComponent.wndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			DlgHsSeiComRev dlgHsSeiComRev = new DlgHsSeiComRev();
			dlgHsSeiComRev.Show(cmdReverSeismicComponent.wndRevit);
			ReverSeismicComponent reverSeismicComponent = new ReverSeismicComponent(base.Doc, dlgHsSeiComRev);
			reverSeismicComponent.Execute();
			dlgHsSeiComRev.Close();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle wndRevit = null;
	}
}
